#include "soundManager.h"


soundManager::soundManager()
{
	deadASound.loadSound("sounds/dead_team_a.wav");
	deadBSound.loadSound("sounds/dead_team_b.wav");
	scoreASound.loadSound("sounds/score_team_a.wav");
	scoreBSound.loadSound("sounds/score_team_b.wav");
	collisionsSound.loadSound("sounds/collision.wav");
	endSound.loadSound("sounds/end_of_game.wav");
	backgroundSound.loadSound("sounds/background.wav");
	shootSound.loadSound("sounds/shoot.wav");
	startSound.loadSound("sounds/start_of_game.wav");
	// team A
	shootingSound1.loadSound("sounds/loading_gun.wav");
	shootingSound2.loadSound("sounds/loading_gun.wav");
	shootingSound3.loadSound("sounds/loading_gun.wav");
	shootingSound4.loadSound("sounds/loading_gun.wav");
	// team B
	shootingSound5.loadSound("sounds/loading_gun.wav");
	shootingSound6.loadSound("sounds/loading_gun.wav");
	shootingSound7.loadSound("sounds/loading_gun.wav");
	shootingSound8.loadSound("sounds/loading_gun.wav");
	preparationSound.loadSound("sounds/preparation.wav");
}

soundManager::~soundManager()
{

}
/*
* preparation game
*/
void soundManager::preparation()
{
	preparationSound.play();
	preparationSound.setLoop(true);
}

void soundManager::preparationStop()
{
	preparationSound.stop();
}
/*
* start game
*/
void soundManager::start()
{
	startSound.play();
	startSound.setLoop(true);
}
/*
* stop start sound
*/
void soundManager::startStop()
{
	startSound.stop();
}
/*
* while is shooting
*/
void soundManager::shooting(int team, int id)
{
	if(team==2) id= id+4;
	switch(id)
	{
	case 0:
		if(shootingSound1.getIsPlaying())break;
		shootingSound1.play();
		shootingSound1.setLoop(true);
		shootingSound1.setVolume(0.5f);
		break;
	case 1:
		if(shootingSound2.getIsPlaying())break;
		shootingSound2.play();
		shootingSound2.setLoop(true);
		shootingSound2.setVolume(0.5f);
		break;
	case 2:
		if(shootingSound3.getIsPlaying())break;
		shootingSound3.play();
		shootingSound3.setLoop(true);
		shootingSound3.setVolume(0.5f);
		break;
	case 3:
		if(shootingSound4.getIsPlaying())break;
		shootingSound4.play();
		shootingSound4.setLoop(true);
		shootingSound4.setVolume(0.5f);
		break;
	case 4:
		if(shootingSound5.getIsPlaying())break;
		shootingSound5.play();
		shootingSound5.setLoop(true);
		shootingSound5.setVolume(0.5f);
		break;
	case 5:
		if(shootingSound6.getIsPlaying())break;
		shootingSound6.play();
		shootingSound6.setLoop(true);
		shootingSound6.setVolume(0.5f);
		break;
	case 6:
		if(shootingSound7.getIsPlaying())break;
		shootingSound7.play();
		shootingSound7.setLoop(true);
		shootingSound7.setVolume(0.5f);
		break;
	case 7:
		if(shootingSound8.getIsPlaying())break;
		shootingSound8.play();
		shootingSound8.setLoop(true);
		shootingSound8.setVolume(0.5f);
		break;	
	}
}
/*
* event shooting stop
*/
void soundManager::shootingStop(int team, int id)
{
	if(team==2) id= id+4;
	switch(id)
	{
	case 0:
		shootingSound1.stop();
		break;
	case 1:
		shootingSound2.stop();
		break;
	case 2:
		shootingSound3.stop();
		break;
	case 3:
		shootingSound4.stop();
		break;
	case 4:
		shootingSound5.stop();
		break;
	case 5:
		shootingSound6.stop();
		break;
	case 6:
		shootingSound7.stop();
		break;
	case 7:
		shootingSound8.stop();
		break;	
	}
}
/*
* event shooting
*/
void soundManager::shoot()
{
	shootSound.play();
}
/*
* event dead
*/
void soundManager::dead(int team)
{
	if(team==1)
	{
		deadASound.play();
	}else{
		deadBSound.play();
	}
}
/*
* event score
*/
void soundManager::score(int team)
{
	if(team==1)
	{
		scoreASound.play();
	}else{
		scoreASound.play();
	}
}
/*
* event collisions
*/
void soundManager::collisions(char side)
{
	if(side=='W' || side==' '){collisionsSound.setPan(0.5);collisionsSound.setVolume(1.0f);}
	if(side=='E'){collisionsSound.setPan(0.5);collisionsSound.setVolume(1.0f);}
	if(side=='S'){collisionsSound.setPan(0.2);collisionsSound.setVolume(1.0f);}
	if(side=='N'){collisionsSound.setPan(0.8);collisionsSound.setVolume(1.0f);}
	collisionsSound.play();
}
/*
* event end game
*/
void soundManager::end()
{
	endSound.play();
	endSound.setLoop(true);
}

void soundManager::endStop()
{
	endSound.stop();
}
/*
* event background game
*/
void soundManager::background()
{
	backgroundSound.play();
	backgroundSound.setLoop(true);
}
void soundManager::backgroundStop()
{
	backgroundSound.stop();
}